<?php

	// TITLE: Project_status_change AUTO MODEL
	// FILE: scaffolding/model/project_status_change.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createProjectStatusChange = function($con, $projectStatusChange) {
		$sql = 'INSERT INTO project_status_change (project_id, status_id, when_changed, who_changed, when_authorized, who_authorized) VALUES (';
		$sql .= $project_status_change->getProjectId() . ', ';
		$sql .= $project_status_change->getStatusId() . ', ';
		$sql .= $project_status_change->getWhenChanged() . ', ';
		$sql .= $project_status_change->getWhoChanged() . ', ';
		$sql .= $project_status_change->getWhenAuthorized() . ', ';
		$sql .= $project_status_change->getWhoAuthorized() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readProjectStatusChange = function($con, $id) {
		$sql = 'SELECT * FROM project_status_change WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$projectStatusChange = new ProjectStatusChange();
			$projectStatusChange->setProjectId($dbio->select($readProject(result[0])));
			$projectStatusChange->setStatusId($dbio->select($readStatus(result[1])));
			$projectStatusChange->setWhenChanged(result[2]);
			$projectStatusChange->setWhoChanged(result[3]);
			$projectStatusChange->setWhenAuthorized(result[4]);
			$projectStatusChange->setWhoAuthorized(result[5]);
		} else {
			$projectStatusChange = false;
		}
		return $projectStatusChange;
	};

	$updateProjectStatusChange = function($con, $projectStatusChange) {
		$sql = 'UPDATE project_status_change SET ';
		$sql .= 'project_id = ' . $project_status_change->getProjectId() . ', ';
		$sql .= 'status_id = ' . $project_status_change->getStatusId() . ', ';
		$sql .= 'when_changed = ' . $project_status_change->getWhenChanged() . ', ';
		$sql .= 'who_changed = ' . $project_status_change->getWhoChanged() . ', ';
		$sql .= 'when_authorized = ' . $project_status_change->getWhenAuthorized() . ', ';
		$sql .= 'who_authorized = ' . $project_status_change->getWhoAuthorized() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteProjectStatusChange = function($con, $id) {
		$sql = 'DELETE FROM project_status_change WHERE project_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listProjectStatusChange = function($con) {
		$sql = 'SELECT * FROM project_status_change';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$projectStatusChanges = array();
			while ($result = mysqli_fetch_array($results)) {
				$projectStatusChange = new ProjectStatusChange();
				$projectStatusChange->setProjectId($dbio->select($readProject(result[0])));
				$projectStatusChange->setStatusId($dbio->select($readStatus(result[1])));
				$projectStatusChange->setWhenChanged(result[2]);
				$projectStatusChange->setWhoChanged(result[3]);
				$projectStatusChange->setWhenAuthorized(result[4]);
				$projectStatusChange->setWhoAuthorized(result[5]);
				$projectStatusChanges[] = projectStatusChange;
			}// end while
		} else {
			$projectStatusChanges = false;
		}
		return $projectStatusChanges;
	};

